/*----------------------------------------------------------------------------
 * MainBirth
 * ---------------------------------------------------------------------------
 * Date      : 2011-02-08
 * Author    : naiyumie
 * ---------------------------------------------------------------------------
 * USAGE
 * ---------------------------------------------------------------------------
 *
 * ---------------------------------------------------------------------------
 * EXAMPLE
 * ---------------------------------------------------------------------------
 *
 *----------------------------------------------------------------------------
 */
$.fn.MainBirth	= function (option)
{
	option = option || {};

	var element		= $(this);
	var interval	= null;
	var current		= 0;
	var delay		= option.delay ? option.delay : 3000;
	var banner		= $(element).children('div.birth-people');
	var size		= parseInt($(banner).children('ul').size());
	var is_focus	= false;

	if (size<2) { return; }

	$(banner).css('overflow', 'hidden').children('ul').each(function(i)
	{
		if (i>0) { $(this).hide(); }
	});

	var function_href	= $(element).attr('id');
	var popupzone_functions	= '<ul class="btn-control">';
		popupzone_functions	+= '<li><a href="#' + function_href + '" class="btn-play"><img src="./images/main2/btn_line_play.gif" alt="play" /></a></li>';
		popupzone_functions	+= '<li><a href="#' + function_href + '" class="btn-stop"><img src="./images/main2/btn_line_stop.gif" alt="stop" /></a></li>';
		popupzone_functions	+= '</ul>';

		$(element).children('div.birth-people').before(popupzone_functions);
		$(element).children('ul.btn-control').find('a.btn-play').click(function()
		{
			interval	= setInterval(rotate, delay);
			return false;
		});

		$(element).children('ul.btn-control').find('a.btn-stop').click(function()
		{
			clearInterval(interval);
			return false;
		});
	var rotate	= function ()
	{
		current++;

		if (current>=size) { current = 0; }

		$(banner).children('ul').hide();
		$(banner).children('ul:nth-child('+(current+1)+')').show();
	};

	interval	= setInterval(rotate, delay);
};